package cn.edu.pku.ss.lbs.stub;

import cn.edu.pku.ss.lbs.position.SignalRecord;
import cn.edu.pku.ss.lbs.position.SignalSource;

import java.util.ArrayList;
import java.util.List;

public class MockSignalSource extends SignalSource implements Runnable {
    private final long startTime = System.currentTimeMillis();

    private List<SignalRecord> signalRecords = new ArrayList<SignalRecord>();

    public MockSignalSource() {
        signalRecords.add(new SignalRecord("theNode01", "theTerminal", -50, startTime + 1000));
        signalRecords.add(new SignalRecord("theNode02", "theTerminal", -40, startTime + 6000));
        new Thread(this).start();
    }

    public void run() {
        try {
            long time = startTime;
            for (SignalRecord signal : signalRecords) {
                Thread.sleep(signal.getTime() - time);
                notifyProcessors(signal);
                time = signal.getTime();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}